package com.ruoyi.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SaleOrderDelivery;
import com.ruoyi.system.service.ISaleOrderDeliveryService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 销售订单发货记录Controller
 * 
 * @author ruoyi
 * @date 2025-06-16
 */
@Controller
@RequestMapping("/sale_order_delivery/delivery")
public class SaleOrderDeliveryController extends BaseController
{
    private String prefix = "sale_order_delivery/delivery";

    @Autowired
    private ISaleOrderDeliveryService saleOrderDeliveryService;

    @RequiresPermissions("sale_order_delivery:delivery:view")
    @GetMapping()
    public String delivery()
    {
        return prefix + "/delivery";
    }

    /**
     * 查询销售订单发货记录列表
     */
    @RequiresPermissions("sale_order_delivery:delivery:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SaleOrderDelivery saleOrderDelivery)
    {
        startPage();
        List<SaleOrderDelivery> list = saleOrderDeliveryService.selectSaleOrderDeliveryList(saleOrderDelivery);
        return getDataTable(list);
    }

    /**
     * 导出销售订单发货记录列表
     */
    @RequiresPermissions("sale_order_delivery:delivery:export")
    @Log(title = "销售订单发货记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SaleOrderDelivery saleOrderDelivery)
    {
        List<SaleOrderDelivery> list = saleOrderDeliveryService.selectSaleOrderDeliveryList(saleOrderDelivery);
        ExcelUtil<SaleOrderDelivery> util = new ExcelUtil<SaleOrderDelivery>(SaleOrderDelivery.class);
        return util.exportExcel(list, "销售订单发货记录数据");
    }

    /**
     * 新增销售订单发货记录
     */
    @RequiresPermissions("sale_order_delivery:delivery:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存销售订单发货记录
     */
    @RequiresPermissions("sale_order_delivery:delivery:add")
    @Log(title = "销售订单发货记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SaleOrderDelivery saleOrderDelivery)
    {
        return toAjax(saleOrderDeliveryService.insertSaleOrderDelivery(saleOrderDelivery));
    }

    /**
     * 修改销售订单发货记录
     */
    @RequiresPermissions("sale_order_delivery:delivery:edit")
    @GetMapping("/edit/{deliveryId}")
    public String edit(@PathVariable("deliveryId") Long deliveryId, ModelMap mmap)
    {
        SaleOrderDelivery saleOrderDelivery = saleOrderDeliveryService.selectSaleOrderDeliveryByDeliveryId(deliveryId);
        mmap.put("saleOrderDelivery", saleOrderDelivery);
        return prefix + "/edit";
    }

    /**
     * 修改保存销售订单发货记录
     */
    @RequiresPermissions("sale_order_delivery:delivery:edit")
    @Log(title = "销售订单发货记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SaleOrderDelivery saleOrderDelivery)
    {
        return toAjax(saleOrderDeliveryService.updateSaleOrderDelivery(saleOrderDelivery));
    }

    /**
     * 删除销售订单发货记录
     */
    @RequiresPermissions("sale_order_delivery:delivery:remove")
    @Log(title = "销售订单发货记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(saleOrderDeliveryService.deleteSaleOrderDeliveryByDeliveryIds(ids));
    }
}
